package com.djq.project.mq.consumer.routing;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RoutingConfig {
    public final static String  DIRECT_EXCHANGE="routing_exchange";
    public final static String  DIRECT_EXCHANGE_QUEUE1="routing1";
    public final static String  DIRECT_EXCHANGE_QUEUE2="routing2";

    //创建一个direct交换机
    @Bean
    DirectExchange directExchange1() {
        return new DirectExchange(DIRECT_EXCHANGE);
    }
    @Bean
    public Queue routingQueue1() {
        return new Queue(DIRECT_EXCHANGE_QUEUE1, true);
    }

    @Bean
    public Queue routingQueue2() {
        return new Queue(DIRECT_EXCHANGE_QUEUE2, true);
    }

    //将direct.A队列绑定到directExchange交换机中，使用direct.a.key作为路由规则
    @Bean
    Binding bindingExchangeMessageDirectA(Queue routingQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(routingQueue1).to(directExchange).with("direct.routing1.key");
    }

    @Bean
    Binding bindingExchangeMessageDirectB(Queue routingQueue2, DirectExchange directExchange) {
        return BindingBuilder.bind(routingQueue2).to(directExchange).with("direct.routing2.key");
    }

}
